﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace protoNet
{
    public class NetDealer : Singleton<NetDealer>
    {
        public void Send(string url, byte[] msg)
        {
            StartCoroutine(POST(url, msg));
        }

        private IEnumerator POST(string url, byte[] msg)
        {
            // 发送数据
            WWW www = new WWW(url, msg);
            yield return www;

            if (www.error != null)
            {
                //POST失败
                _G.Print(www.error);
            }
            else
            {
                if (www.bytes.Length == 0)
                {
                    _G.Print("Received error message, data size = 0");
                }
                else
                {
                    _G.Print("Received message, start deserialize...");
                    MsgReader.ReadMessage(www.bytes);
                }
            }
        }
    }
}
